<script type="text/javascript">
  function refreshParent() {
    window.opener.location.href = window.opener.location.href;
    if (window.opener.progressWindow){
      window.opener.progressWindow.close()
    }
    window.close();
  }
</script>
<h3>Group Score &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= <%=@game.game_setting.price_weight%>[SoldFlag x (N+1-PriceRank)/N] + <%=1-@game.game_setting.price_weight%>[ActionFlag x (N+1-ActionRank)/N]</h3>
<h3>Group Share(%) = Your Score/Total Score</h3>
<center>
<span style="font-size:40px;">Remains:</span> <span style="font-size:60px; color:red;"><%if @game.game_setting.show_market=='N'%><%=number_with_delimiter(@game.market_remain)%><%else%>?<%end%></span>
</center>
<form action="/game_runnings/calculate_share/<%=@game.gencode%>" method="post">
<table width="100%" style="border: 3px solid black; font-size: 25px;">
  <tr align="center" style="border: 3px solid black;" bgcolor="#cccccc">
    <th>Group</th>
    <th>SoldFlag</th>
    <th>PriceRank</th>
    <th>ActionFlag</th>
    <th>ActionRank</th>
    <%if @game.game_setting.promotion=='Y'%>
    <th>Promotion</th>
    <%end%>
    <th>Score</th>
    <th>Share(%)</th>
  </tr>
<%
  price_array = Array.new
  @players.each do |p|
  sale = Sale.find(:first, :conditions=>["game_id=? AND year=? AND round=? AND player_id=?", @game.id, @game.current_year, @game.current_round, p.id])
    price_array = price_array << sale.price
  end
  price_rank = array_rank(price_array)
%>
<%@players.each_with_index do |p,i|%>
  <%sale = Sale.find(:first, :conditions=>["game_id=? AND year=? AND round=? AND player_id=?", @game.id, @game.current_year, @game.current_round, p.id])%>
  <tr align="center">
    <td align="left"><%=p.name%></td>
    <td>
      <%
        sold_flag = 0
        if sale.sale_flag=='Y'
          sold_flag = 1
        end
      %>
      <input type="text" style="width:80px;" name="sold_flag_<%=p.id%>" value="<%=sold_flag%>"/>
    </td>
    <td>
      <input type="text" style="width:80px;" name="price_rank_<%=p.id%>" value="<%=price_rank[i]%>"/>
    </td>
    <td>
      <input type="text" style="width:80px;" name="action_flag_<%=p.id%>" value="1"/>
    </td>
    <td>
      <input type="text" style="width:80px;" name="action_rank_<%=p.id%>" value="<%=sale.action_rank%>"/>
    </td>
    <%if @game.game_setting.promotion=='Y'%>
    <td><%=number_with_delimiter(sale.promotion, :delimiter=>",")%></td>
    <%end%>
    <td>
      <%=number_with_precision(sale.score, :precision=>2, :delimiter=>",")%>
    </td>
    <td>
      <%=number_with_precision(sale.remain_share * 100, :precision=>2, :delimiter=>",")%>
    </td>
  </tr>
<%end%>
</table><br/>
<center>
  <%if @game.game_setting.promotion=='Y'%>
  <input type="submit" id="prank" name="prank" value="Promotion Rank"/>
  <%end%>
  <input type="submit" id="cal" name="cal" value="Calulate"/>
  <input type="submit" id="al" name="al" value="Allocate"/>
</center>
</form>